package com.clz.appdesign.myapp

import com.clz.appdesign.kotlin.Animal
import org.junit.Test

class KotlinTest {
    /**
     * 测试Kotlin高阶函数
     */
    @Test
    fun testKotlinGaoJieHanShu() {
        val string_array:Array<String> = arrayOf("How","do","you","do")
        val maxCustom = maxCustom(string_array) { a, b -> a.length > b.length }
        println(maxCustom)
    }

    fun <T> maxCustom(array: Array<T>, greater: (T, T) -> Boolean): T? {
        var max: T? = null
        for (item in array) {
            if (max == null || greater(item, max)) {
                max = item
            }
        }
        return max
    }

    @Test
    fun testConstructor(){
        var animal:Animal = Animal(18,"ZS")
        var animal2:Animal = Animal(18,"ZS",1)
        print(animal.age)
    }
}